home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-12 | 11.3 KB | 484 lines | [TEXT/KAHL] |
- //--------------------------------------------------------------------------
- //
- // MakeMyMediaMovies.
- // by John Wang
- //
- // Description: Create movies for QuickDraw media.
- //
- // Version: 1.0 02/25/93 New.
- //
- //--------------------------------------------------------------------------
-
- //
- // #defines
- //
-
- #define APPLEID 128
- #define ABOUTMECOMMAND 1
-
- #define CREATEID 129
- #define CREATE_ROWS 1
- #define CREATE_LINES 2
- #define CREATE_BOXES 3
- #define CREATE_BALL 4
- #define FILE_QUIT 6
-
- #define MAXWINDOWS 5
-
- //
- // #includes
- //
-
- #include <GestaltEqu.h>
- #include <Movies.h>
- #include "QDrawHandler.h"
-
- //
- // Global Variables.
- //
-
- Boolean DoneFlag;
- WindowPtr MyWindow;
-
- //--------------------------------------------------------------------------
-
- waitClick()
- {
- do {
- } while (!Button());
- do {
- } while (Button());
- }
-
- //--------------------------------------------------------------------------
-
- void doRows(Media myMedia, short myWidth, short myHeight, Rect *windRect)
- {
- long i;
- Rect drawRect;
- RGBColor myColor;
- PicHandle myPict;
- QDrawDescriptionHandle myQDDesc;
-
- // Add samples to media.
- myQDDesc = (QDrawDescriptionHandle) NewHandle(sizeof(QDrawDescription));
- (**myQDDesc).size = sizeof(QDrawDescription);
- (**myQDDesc).type = QDrawMediaType;
- (**myQDDesc).version = QDMediaVersion;
- SetRect(&drawRect, 0, 0, 500, 80);
- for (i=0; i<10; i++) {
- short mySync;
-
- myPict = OpenPicture(windRect);
- if (i==0) {
- EraseRect(windRect);
- mySync = 0;
- } else {
- mySync = mediaSampleNotSync;
- }
- myColor.red = myColor.green = myColor.blue = (i*25) << 8;
- RGBForeColor(&myColor);
- PaintRect(&drawRect);
- ClosePicture();
- if (AddGraphics(myMedia, myPict, myQDDesc, 600, mySync, nil)) {
- DebugStr("\PAddMediaSample failed.");
- ExitToShell();
- }
- DrawPicture(myPict, windRect);
- KillPicture(myPict);
- OffsetRect(&drawRect, 0, 40);
- }
- }
-
- //--------------------------------------------------------------------------
-
- void doLines(Media myMedia, short myWidth, short myHeight, Rect *windRect)
- {
- long i;
- Rect drawRect;
- RGBColor myColor;
- PicHandle myPict;
- QDrawDescriptionHandle myQDDesc;
-
- // Add samples to media.
- if (BeginMediaEdits(myMedia)) {
- DebugStr("\PBeginMediaEdits failed.");
- ExitToShell();
- }
- myQDDesc = (QDrawDescriptionHandle) NewHandle(sizeof(QDrawDescription));
- (**myQDDesc).size = sizeof(QDrawDescription);
- (**myQDDesc).type = QDrawMediaType;
- (**myQDDesc).version = QDMediaVersion;
- SetRect(&drawRect, 0, 0, myWidth, myHeight);
- for (i=0; i<myWidth; i++) {
- short mySync;
-
- myPict = OpenPicture(windRect);
- myColor.red = (i & 0xff) << 8;
- myColor.green = ((255 - i) & 0xff) << 8;
- myColor.blue = ((128 - i) & 0xff) << 8;
- if (i==0) {
- EraseRect(windRect);
- mySync = 0;
- } else {
- mySync = mediaSampleNotSync;
- }
- RGBForeColor(&myColor);
- MoveTo(i,0);
- LineTo(i,myHeight);
- ClosePicture();
- DrawPicture(myPict, windRect);
- if (AddGraphics(myMedia, myPict, myQDDesc, 20, mySync, nil)) {
- DebugStr("\PAddMediaSample failed.");
- ExitToShell();
- }
- KillPicture(myPict);
- }
- }
-
- //--------------------------------------------------------------------------
-
- void doBoxes(Media myMedia, short myWidth, short myHeight, Rect *windRect)
- {
- long i;
- Rect drawRect;
- RGBColor myColor;
- PicHandle myPict;
- QDrawDescriptionHandle myQDDesc;
-
- // Add samples to media.
- if (BeginMediaEdits(myMedia)) {
- DebugStr("\PBeginMediaEdits failed.");
- ExitToShell();
- }
- myQDDesc = (QDrawDescriptionHandle) NewHandle(sizeof(QDrawDescription));
- (**myQDDesc).size = sizeof(QDrawDescription);
- (**myQDDesc).type = QDrawMediaType;
- (**myQDDesc).version = QDMediaVersion;
- SetRect(&drawRect, 0, 0, myWidth, myHeight);
- for (i=0; i<50; i++) {
- short mySync;
-
- myPict = OpenPicture(windRect);
- myColor.red = ((i*10) & 0xFF) << 8;
- myColor.green = ((i*20) & 0xFF) << 8;
- myColor.blue = ((i*30) & 0xFF) << 8;
- RGBForeColor(&myColor);
- if (i==0) {
- EraseRect(windRect);
- mySync = 0;
- } else {
- mySync = mediaSampleNotSync;
- }
- PaintRect(&drawRect);
- ClosePicture();
- DrawPicture(myPict, windRect);
- InsetRect(&drawRect, myWidth / 100, myHeight / 100);
- if (AddGraphics(myMedia, myPict, myQDDesc, 40, mySync, nil)) {
- DebugStr("\PAddMediaSample failed.");
- ExitToShell();
- }
- KillPicture(myPict);
- }
- }
-
- //--------------------------------------------------------------------------
-
- void doBall(Media myMedia, short myWidth, short myHeight, Rect *windRect)
- {
- long i;
- Rect drawRect;
- RGBColor myColor;
- PicHandle myPict;
- QDrawDescriptionHandle myQDDesc;
- short lx, ly, x, y, vx, vy;
-
- // Add samples to media.
- if (BeginMediaEdits(myMedia)) {
- DebugStr("\PBeginMediaEdits failed.");
- ExitToShell();
- }
- myQDDesc = (QDrawDescriptionHandle) NewHandle(sizeof(QDrawDescription));
- (**myQDDesc).size = sizeof(QDrawDescription);
- (**myQDDesc).type = QDrawMediaType;
- (**myQDDesc).version = QDMediaVersion;
- SetRect(&drawRect, 0, 0, 30, 30);
- EraseRect(windRect);
- lx = ly = x = y = 10;
- vx = 5, vy = 3;
- for (i=0; i<1000; i++) {
- short mySync;
-
- myPict = OpenPicture(windRect);
- if ((i % 10) == 0) {
- mySync = 0;
- myColor.red = ((i*15) & 0xFF) << 8;
- myColor.green = ((i*10) & 0xFF) << 8;
- myColor.blue = ((i*5) & 0xFF) << 8;
- RGBBackColor(&myColor);
- EraseRect(windRect);
- } else {
- mySync = mediaSampleNotSync;
- }
- myColor.red = ((i*5) & 0xFF) << 8;
- myColor.green = ((i*10) & 0xFF) << 8;
- myColor.blue = ((i*15) & 0xFF) << 8;
- RGBForeColor(&myColor);
- SetRect(&drawRect, lx-15, ly-15, lx+15, ly+15);
- EraseOval(&drawRect);
- SetRect(&drawRect, x-15, y-15, x+15, y+15);
- PaintOval(&drawRect);
- lx = x;
- ly = y;
- x += vx;
- y += vy;
- if (x > myWidth) {
- x = myWidth;
- vx = -vx;
- } else if (x < 0) {
- x = 0;
- vx = -vx;
- }
- if (y > myHeight) {
- y = myHeight;
- vy = -vy;
- } else if (y < 0) {
- y = 0;
- vy = -vy;
- }
- ClosePicture();
- DrawPicture(myPict, windRect);
- if (AddGraphics(myMedia, myPict, myQDDesc, 40, mySync, nil)) {
- DebugStr("\PAddMediaSample failed.");
- ExitToShell();
- }
- KillPicture(myPict);
- }
- }
-
- //--------------------------------------------------------------------------
-
- void makeMovie(ProcPtr myFunc(Media myMedia, short myWidth, short myHeight, Rect *windRect), short myWidth, short myHeight)
- {
- OSErr err;
- Rect windRect;
- StandardFileReply reply;
- short resRefNum;
- Movie myMovie;
- Track myTrack;
- Media myMedia;
-
- // Set window size and rect.
- SizeWindow(MyWindow, myWidth, myHeight, FALSE);
- SetRect(&windRect, 0, 0, myWidth, myHeight);
- EraseRect(&windRect);
-
- // Create file.
- StandardPutFile("\PName of movie file to create:", "\PUntitled", &reply);
- if (!reply.sfGood)
- ExitToShell();
- if (CreateMovieFile(&reply.sfFile, 'TVOD', 0,
- createMovieFileDeleteCurFile, &resRefNum, &myMovie)) {
- DebugStr("\PCreateMovieFile failed.");
- ExitToShell();
- }
-
- // Create track and media.
- if ((myTrack = NewMovieTrack(myMovie, (long) myWidth << 16, (long) myHeight << 16, 0)) == nil) {
- DebugStr("\PNewMovieTrack failed.");
- ExitToShell();
- }
- if ((myMedia = NewTrackMedia(myTrack, QDrawMediaType, 600, nil, (OSType) nil)) == nil) {
- DebugStr("\PNewTrackMedia failed. Is the QuickDraw Media handler installed?");
- ExitToShell();
- }
-
- // Start editing session.
- if (BeginMediaEdits(myMedia)) {
- DebugStr("\PBeginMediaEdits failed.");
- ExitToShell();
- }
-
- // Call function to add media
- (myFunc) (myMedia, myWidth, myHeight, &windRect);
-
- // Place media into movie and save movie.
- if (EndMediaEdits(myMedia)) {
- DebugStr("\PEndMediaEdits failed.");
- ExitToShell();
- }
- if (InsertMediaIntoTrack(myTrack, 0, 0, GetMediaDuration(myMedia), kFix1)) {
- DebugStr("\PInsertMediaIntoTrack failed.");
- ExitToShell();
- }
-
- // Save movie and close file.
- if (AddMovieResource( myMovie, resRefNum, nil, nil)) {
- DebugStr("\PAddMovieResource failed.");
- ExitToShell();
- }
- if (CloseMovieFile(resRefNum)) {
- DebugStr("\PCloseMovieFile failed.");
- ExitToShell();
- }
- DisposeMovie(myMovie);
- }
-
- //--------------------------------------------------------------------------
-
- void init()
- {
- OSErr err;
- long QDfeature, QTfeature;
- Handle myHandle;
- Rect myRect;
-
- // Initialize Managaer.
- MaxApplZone();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MoreMasters(); InitGraf(&qd.thePort);
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitDialogs(nil);
- InitCursor();
-
- // Use Gestalt to find if QuickTime is avaiable.
- // Use Gestalt to find out version of ColorSync available
- if (Gestalt(gestaltQuickdrawVersion, &QDfeature))
- ExitToShell();
- if (QDfeature < 0x0230)
- ExitToShell();
- if (Gestalt(gestaltQuickTime, &QTfeature))
- QTfeature = 0;
- if ((QTfeature >> 16) < 0x0150)
- ExitToShell();
-
- // Set up menus.
- myHandle = GetNewMBar(128);
- SetMenuBar(myHandle);
- AddResMenu(GetMHandle(APPLEID), 'DRVR');
- DrawMenuBar();
-
- // Initialize global variables.
- DoneFlag = FALSE;
-
- // Open QuickTime last.
- if (EnterMovies())
- ExitToShell();
-
- // Define output window.
- SetRect(&myRect, 10, 40, 510, 440);
- MyWindow = NewCWindow(nil, &myRect, "\pDisplay graphics", true, documentProc, (WindowPtr) -1, false, 0);
- SetPort(MyWindow);
- }
-
- //--------------------------------------------------------------------------
-
- void doCommand(mResult)
- long mResult;
- {
- int theMenu, theItem;
- char daName[256];
- GrafPtr savePort;
-
- theItem = LoWord(mResult);
- theMenu = HiWord(mResult);
-
- switch (theMenu) {
- case APPLEID:
- if (theItem == ABOUTMECOMMAND) {
- ParamText("\PMakeMyMediaMovies", "\PThis program uses the 'Qdrw' derived media handler to make movies.",
- nil, nil);
- Alert(128, nil);
- } else {
- GetItem(GetMHandle(APPLEID), theItem, daName);
- GetPort(&savePort);
- (void) OpenDeskAcc(daName);
- SetPort(savePort);
- }
- break;
-
- case CREATEID:
- switch (theItem) {
- case CREATE_ROWS:
- makeMovie((ProcPtr) doRows, 500, 400);
- break;
- case CREATE_LINES:
- makeMovie((ProcPtr) doLines, 256, 200);
- break;
- case CREATE_BOXES:
- makeMovie((ProcPtr) doBoxes, 300, 200);
- break;
- case CREATE_BALL:
- makeMovie((ProcPtr) doBall, 500, 400);
- break;
- case FILE_QUIT:
- DoneFlag = TRUE;
- break;
- default:
- break;
- }
- break;
- }
- HiliteMenu(0);
- return;
- }
-
- //--------------------------------------------------------------------------
-
- main()
- {
- int i;
- EventRecord myEvent;
- WindowPtr whichWindow;
-
- init();
- for ( ;; ) {
-
- // We can't just do ExitToShell because we must call ExitMovies.
- if (DoneFlag)
- ExitToShell();
-
- if (WaitNextEvent(everyEvent, &myEvent, 0, nil)) {
- switch (myEvent.what) {
- case mouseDown:
- switch (FindWindow(myEvent.where, &whichWindow)) {
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
- case inMenuBar:
- doCommand(MenuSelect(myEvent.where));
- break;
- case inContent:
- break;
- case inDrag:
- SelectWindow(whichWindow);
- DragWindow (whichWindow, myEvent.where, &qd.screenBits.bounds);
- break;
- case inGoAway:
- case inGrow:
- case inZoomIn:
- case inZoomOut:
- default:
- break;
- }
- break;
- case keyDown:
- case autoKey:
- if ( myEvent.modifiers & cmdKey )
- if ( myEvent.what == keyDown )
- doCommand(MenuKey(myEvent.message & charCodeMask));
- break;
- case updateEvt:
- break;
- case diskEvt:
- case activateEvt:
- case app4Evt:
- default:
- break;
- }
- }
- }
- }